#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys

event_dict={}
with open(sys.argv[1]) as event_conf_file:
    for line in event_conf_file:
        if len(line.strip("\n").split("\001"))!=5:
            continue
        ceid,cid,sid,eid,times=line.strip("\n").split("\001")
        k=eid.strip()+cid.strip()+sid.strip()
        event_dict[k]=[times.strip(),ceid,cid,sid,eid]

for data in sys.stdin:
    if len(data.strip("\n").split("\t"))!=5:
        continue
    cid,sid,session,nasid,eventids=data.strip("\n").split("\t")
    event_count={}
    for eventid in eventids.split(","):
        event_count[eventid.strip()]=event_count.get(eventid.strip(),0) + 1
    for eventid in event_count:

        k=eventid+cid.strip()+sid.strip()
        if k in event_dict:
            if int(event_dict[k][0]) <= event_count[eventid]:
                print cid+"\t"+sid+"\t"+nasid+"\t"+event_dict[k][1]+"\t"+eventid+"\t"+"1"

#print cid sid nasid ceid eventid 1